// Ground.cpp: implementation of the CGround class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "YujinSRHost.h"
#include "Ground.h"
#include "MainFrm.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CGround::CGround()
{
	m_BrushOfBall.CreateSolidBrush(RGB(255,127,0)); 
	this->m_PenWhite.CreatePen(PS_SOLID,1,RGB(255,255,255));  
}

CGround::~CGround()
{
	m_BrushOfBall.DeleteObject(); 
	m_PenWhite.DeleteObject(); 
}

void CGround::Draw(int x,int y,CDC *pDC)
{
	CDC cdc;
	CBitmap m_Bitmap;
	CBitmap *m_pOldBitmap;
	CRect rectBall;
	CBrush *oldBrush;
	CPen   *oldPen;
	double CONV_x =0;
	double CONV_y =0;
	
	CONV_x = 2.66;
	CONV_y = 2.66;

	m_BitGround.LoadBitmap(IDB_BITMAP1); 
	cdc.CreateCompatibleDC(pDC);
	m_Bitmap.CreateCompatibleBitmap(pDC,640,480); 
	m_pOldBitmap=cdc.SelectObject(&m_BitGround);
	
	/////////////////////Draw ball////////////////////////////////////////
	rectBall.left   = (int)(((CMainFrame*)AfxGetMainWnd())->pView->m_CGame.Ball.position.X*CONV_x-7);
	rectBall.top    = (int)((GROUNDHEIGHT-((CMainFrame*)AfxGetMainWnd())->pView->m_CGame.Ball.position.Y)*CONV_y-7);
	rectBall.right  = (int)(((CMainFrame*)AfxGetMainWnd())->pView->m_CGame.Ball.position.X*CONV_x+7);
	rectBall.bottom = (int)((GROUNDHEIGHT-((CMainFrame*)AfxGetMainWnd())->pView->m_CGame.Ball.position.Y)*CONV_y+7);

	cdc.MoveTo(((CMainFrame*)AfxGetMainWnd())->pView->m_CGame.pGoal);
	cdc.LineTo(((CMainFrame*)AfxGetMainWnd())->pView->m_CGame.pShoot);
	cdc.LineTo(((CMainFrame*)AfxGetMainWnd())->pView->m_CGame.pTarget);

	oldPen   = cdc.SelectObject(&m_PenWhite);
	oldBrush = cdc.SelectObject(&m_BrushOfBall);
	cdc.Ellipse(rectBall);
	cdc.SelectObject(oldBrush); 
	cdc.SelectObject(oldPen); 
	oldBrush->DeleteObject(); 
	oldPen->DeleteObject(); 
	/////////////////////Draw MyRobot////////////////////////////////
	for(int i=0;i<5;i++)
	{
		int Rx = (int)(((CMainFrame*)AfxGetMainWnd())->pView->m_CGame.MyRobot[i].position.X*CONV_x); 
		int Ry = (int)((GROUNDHEIGHT-((CMainFrame*)AfxGetMainWnd())->pView->m_CGame.MyRobot[i].position.Y)*CONV_y);
		int angle = (int)(((CMainFrame*)AfxGetMainWnd())->pView->m_CGame.MyRobot[i].Angle);
		m_CRobotInfo.DrawRobot(Rx,Ry,angle,i+1,&cdc,TRUE);
	}
	/////////////////////Draw OppentRobot////////////////////////////////
	for(i=0;i<5;i++)
	{
		int Rx = (int)(((CMainFrame*)AfxGetMainWnd())->pView->m_CGame.OppRobot[i].position.X*CONV_x); 
		int Ry = (int)((GROUNDHEIGHT-((CMainFrame*)AfxGetMainWnd())->pView->m_CGame.OppRobot[i].position.Y)*CONV_y);
		int angle = (int)(((CMainFrame*)AfxGetMainWnd())->pView->m_CGame.OppRobot[i].Angle);
		m_CRobotInfo.DrawRobot(Rx,Ry,angle,i+1,&cdc,FALSE);
	}
	
	pDC->BitBlt(x,y,640+x,480+y,&cdc,0,0,SRCCOPY);
	cdc.SelectObject(m_pOldBitmap);
	m_pOldBitmap->DeleteObject(); 
	cdc.DeleteDC();
	m_BitGround.DeleteObject(); 
}

void CGround::SetObjectPoint()
{
	

}
